<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function fn(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min
    }

    var value = fn(0, 10)

    var index = 1
    
    // 只能猜3 次

    while(index < 4) {
      index++
      var result  = parseInt(prompt('请输入一个数字'))

      if(result > value) {
        alert('猜大了')
      } else if(result < value) {
        alert('猜小了')
      } else {
        alert('猜对了')
        break
      } 
    }

    if(index === 4) {
      alert('这么笨，小笨蛋')
    }
  </script>
</body>
</html>